//
// Created by Nasa on 2024/2/13.
//
/*
 * https://www.luogu.com.cn/problem/B3851 通过
 2023 年 6 月 GESP C++ 四级编程第 2 题
输入
10
00FFCFAB00FFAC09071B5CCFAB76
00AFCBAB11FFAB09981D34CFAF56
01BFCEAB00FFAC0907F25FCFBA65
10FBCBAB11FFAB09981DF4CFCA67
00FFCBFB00FFAC0907A25CCFFC76
00FFCBAB1CFFCB09FC1AC4CFCF67
01FCCBAB00FFAC0F071A54CFBA65
10EFCBAB11FFAB09981B34CFCF67
01FFCBAB00FFAC0F071054CFAC76
1000CBAB11FFAB0A981B84CFCF66
输出
ABCFFF00CB09AC07101198011B6776FC
321032657CD10E
36409205ACC16D
B41032657FD16D
8F409205ACF14D
324F326570D1FE
3240C245FC411D
BF4032687CD16D
8F409205ACC11D
B240326878D16E
83409205ACE11D
 */

#include <iostream>

using namespace std;

int zh(string a)
{
    int b = 0;
    if (a[0] >= 'A')
    {
        b += (a[0] - 'A' + 10) * 16;
    } else
    {
        b += (a[0] - '0') * 16;
    }
    if (a[1] >= 'A')
    {
        b += a[1] - 'A' + 10;
    } else
    {
        b += a[1] - '0';
    }
    return b;
}

int main()
{
    int n, ct = 0, close, close1 = 0;   //ct:计数,close:离16个灰阶的距离
    string hj;  //用来进制转换(灰阶)
    cin >> n;
    string l[n];
    int t[256] = {0}, l16[16];     //t:桶,l16:16个出现最多的灰阶
    for (int i = 0; i < n; ++i)
    {
        cin >> l[i];
    }
    int intl[n][l[0].size() / 2];   //l的int形式
    for (int i = 0; i < n; ++i)
    {
        for (int j = 1; j < l[0].size(); j += 2)
        {
            hj.push_back(l[i][j - 1]);
            hj.push_back(l[i][j]);
            t[zh(hj)]++;
            intl[i][j / 2] = zh(hj);
            hj = "";
        }
    }
    for (int i = n * l[0].size() / 2; i >= 0; --i)
    {
        for (int j = 0; j < 256; ++j)
        {
//            if (ct == 16)
//            {
//                break;
//            }
            if (t[j] == i)
            {
                l16[ct] = j;
                ct++;
                if (ct == 16)
                {
                    break;
                }
            }
        }
//        if (ct == 16)
//        {
//            break;
//        }
    }
    for (int i : l16)
    {
        printf("%.2X", i);
    }
    cout << endl;
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < l[0].size() / 2; ++j)
        {
            close = 256;
            for (int k = 0; k < 16; ++k)
            {
                if (abs(intl[i][j] - l16[k]) < close)
                {
                    close = abs(intl[i][j] - l16[k]);
                    close1 = k;
                }
            }
//            printf("c:%d,c1:%d  ",close,close1);
            printf("%X", close1);
        }
        cout << endl;
    }
    return 0;
}